﻿@using System.Threading
@using EveKillboard
@using EveKillboard.Content
@using EveKillboard.Core
@model Killmail
@section css{
    <link href="@Url.Content("~/Content/themes/base/minified/jquery-ui.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.mod.css")" rel="stylesheet" type="text/css" /> 
}
@section scripts {
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    @if(Helper.IsDebug()){
        <script src="@Url.Content("~/Content/scripts/fitting.js")" type="text/javascript"></script>
    }
    else{
        <script src="@Url.Content("~/Content/scripts/min/fitting.min.js")" type="text/javascript"></script>
    }
    <script type="text/javascript">
        $(document).ready(function () {
            evekillboard.drawMap();
            var canvas = document.getElementById('fitting');
            canvas.width = 420;
            canvas.height = 420;
            canvas.onmousemove = function(event) { evekillboard.onmouseovercanvas(event,canvas); };
            evekillboard.loadKillmailItems('@string.Format("{0}", Url.Action("KillmailItems", "Killboard"))', @Model.Id, canvas.getContext('2d'));
        });
    </script>
}
@{
    var isInGame = Helper.IsInGame(ViewContext.Controller);
}
<div class="content">
    <div id="raw"><textarea id="rawcontent" readonly="readonly"></textarea></div>
    <div class="killmaildetailsblock">
        <div class="detailHeader">
            <div class="victim">
                <div style="display: inline-block">
                    <img src="@string.Format("http://image.eveonline.com/Character/{0}_64.jpg", Model.Character.EveId.GetValueOrDefault(0))" style="vertical-align: top; margin:0px;" width="64px" height="64px" title="@Model.Character.Name" alt=""/>    
                    <div style=" display: inline-block; width: 32px; border: 1px #323232 solid; ">
                        <img src="@string.Format("http://image.eveonline.com/Corporation/{0}_32.png", Model.Corporation.EveId)"  style="margin:0px; border: 0px;" width="32px" height="32px" title="@Model.Corporation.Name" alt=""/>
                        <img src="@string.Format("http://image.eveonline.com/Alliance/{0}_32.png", Model.Alliance == null ? 0 : Model.Alliance.EveId)" width="32px" height="32px" style="margin:0px; border: 0px;" title="@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", Model.Alliance == null ? Labels.unknown : Model.Alliance.Name)" alt=""/>
                    </div>
                </div>
                <div style="display: inline-block; vertical-align: top;overflow: hidden;white-space: nowrap;width: 270px;">
                    <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : ", Labels.victim)<a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Pilot"), Model.Character.Id)"><b>@Model.Character.Name</b></a></div>
                    <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : ", Labels.corporation)<a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Corporation"), Model.Corporation.Id)">@Model.Corporation.Name</a></div>
                    <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : ", Labels.alliance)
                        @if (Model.Alliance != null){
                            <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Alliance"), Model.Alliance.Id)">@Model.Alliance.Name</a>
                        }
                        else{ <label>@Labels.none</label> }
                    </div>
                </div>
            </div>
            <div class="destroyed">
                <img src="@string.Format("http://image.eveonline.com/Type/{0}_64.png", Model.Destroyed.Id)" title="@string.Format("{0}", Model.Destroyed.Name)" width="64px" height="64px" alt=""/>
                <div>
                    <div><b>@Model.Destroyed.Name</b>&nbsp;(@Model.Destroyed.Group.Name)</div>
                    <div><label id="system">@Model.Location.System</label>&nbsp;(@Model.Location.Security)</div>
                    <div><label id="region">@Model.Location.Region</label></div>
                    <div><label id="date">@string.Format(Thread.CurrentThread.CurrentCulture, "{0}", Model.Date.ToShortDateString())</label></div>
                    <div>@string.Format(Thread.CurrentThread.CurrentCulture, "{0} : {1:N0}", Labels.damage_received, Model.Damage)</div>
                </div>
            </div>
        </div>
        <div class="involvedList">
            <div class="involvedCount"><label>@string.Format(Thread.CurrentThread.CurrentCulture, "{1} : {0:N0}", Model.Involved.Count(), Labels.involved)</label></div>
            <div style="padding: 0px 0 10px 4px;">
                @if(Model.Involved.Count() > 1){
                    foreach (var group in Model.Involved.Where(i => !i.Character.IsNpc.GetValueOrDefault(false) && !i.Character.IsStructure.GetValueOrDefault(false)).Select(i => new { Group = i.Ship != null ? i.Ship.Group.Name : i.Weapon !=null && i.Weapon.Group.Category.Id == 6 ? i.Weapon.Group.Name : Labels.unknown }).GroupBy(i => new { i.Group }).OrderByDescending(g => g.Count()))
                    {
                        <div>@string.Format("{0} : {1}", group.Key.Group, group.Count())</div>
                    }
                }
            </div>
            @foreach (var involved in Model.Involved.OrderByDescending(i => i.Damage))
            {
                <div class="@string.Format("involved {0}", involved.IsFinalBlow ? "finalBlow" : null)">
                    <div class="involvedImagesBlock">
                        @if (involved.Character.IsNpc.GetValueOrDefault(false) || involved.Character.IsStructure.GetValueOrDefault(false))
                        {
                            if (involved.FactionId.HasValue)
                            { <img src="@string.Format("http://image.eveonline.com/Alliance/{0}_64.png", involved.Faction.Id)" width="64px" height="64px" title="@involved.Faction.Name" alt/> }
                            else
                            { <img src="@string.Format("http://image.eveonline.com/Corporation/{0}_64.png", involved.CorporationId.HasValue ? involved.Corporation.EveId : 0)" width="64px" height="64px" title="@involved.Corporation" alt/> }
                        }
                        else
                        { <img src="@string.Format("http://image.eveonline.com/Character/{0}_64.jpg", involved.Character.EveId.HasValue ? involved.Character.EveId : 0)" width="64px" height="64px" style="vertical-align: middle;" title="@involved.Character.Name" alt/> }
                        @if (involved.ShipId.HasValue)
                        { <img src="@string.Format("http://image.eveonline.com/Type/{0}_64.png", involved.Ship.Id)" title="@string.Format("{0}", involved.Ship.Name)" width="64px" height="64px" alt/> }
                        else
                        { <div class="typeUnknown" title="@Labels.unknown"></div> }
                    </div>
                    <div class="involvedDetailsBlock">
                        <div>
                            @if (involved.Character.IsNpc.GetValueOrDefault(false) || involved.Character.IsStructure.GetValueOrDefault(false))
                            {
                                <label><b>@involved.Character.Name</b></label>
                            }
                            else
                            {
                                <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Pilot"), involved.Character.Id)"><b>@involved.Character.Name</b></a>
                            }
                        </div>
                        <div>@if (involved.Corporation != null)
                             {
                                 <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Corporation"), involved.Corporation.Id)">@involved.Corporation.Name</a>
                             }
                             else
                             {
                                 <label>@Labels.unknown</label>
                             }
                        </div>
                        <div>
                            @if (!involved.Character.IsNpc.GetValueOrDefault(false) && involved.Alliance != null)
                            {
                                <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Alliance"), involved.Alliance.Id)">@involved.Alliance.Name</a>
                            }
                            else if (involved.Character.IsNpc.GetValueOrDefault(false) && involved.Faction != null)
                            {
                                <label>@involved.Faction.Name</label>
                            }
                            else
                            {
                                <label>@Labels.none</label>
                            }
                        </div>
                        <div>@if (isInGame)
                             {
                                 @Html.Raw(string.Format("<a class=\"evelink\" href=\"javascript:CCPEVE.showInfo({0})\">{1}</a>", involved.Ship.Id, involved.Ship.Name))
                             }
                             else if (involved.ShipId.HasValue)
                             {
                                 @involved.Ship.Name
                             }
                             else
                             {
                                 @Labels.unknown
                             }
                        </div>
                        <div>
                            @if (isInGame)
                            {
                                @Html.Raw(string.Format("<a class=\"evelink\" href=\"javascript:CCPEVE.showInfo({0})\">{1}</a>", involved.Weapon.Id, involved.Weapon.Name))
                            }
                            else if (involved.WeaponId.HasValue)
                            {
                                @involved.Weapon.Name
                            }
                            else
                            {
                                @Labels.unknown
                            }
                        </div>
                    </div>
                    <div class="involvedDamage">@string.Format(Thread.CurrentThread.CurrentCulture, "{2} : {0:N0} ({1:P2})", involved.Damage, decimal.Divide(involved.Damage, Model.Damage == 0 ? 1 : Model.Damage), Labels.damage_done)</div>
                </div>
            }
        </div>
        <div class="fittingcontainer">
            <div class="fittingview"><canvas class="fittingcanva" id="fitting"></canvas></div>
            <div class="killmailItems">
                @if (Model.ItemsFittedHighSlot.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="highSlot" src alt/><label>High Slot</label></div>
                        @foreach (var module in Model.ItemsFittedHighSlot.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                        @foreach (var module in Model.ChargesHighSlot)
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsFittedMedSlot.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="medSlot" src alt /><label>Medium Slot</label></div>
                        @foreach (var module in Model.ItemsFittedMedSlot.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                        @foreach (var module in Model.ChargesMedSlot)
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsFittedLowSlot.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="lowSlot" src alt/><label>Low Slot</label></div>
                        @foreach (var module in Model.ItemsFittedLowSlot.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsFittedSubSlot.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="subsystemSlot" src alt/><label>Subsystems</label></div>
                        @foreach (var module in Model.ItemsFittedSubSlot.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsFittedRigSlot.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="rigSlot" src alt/><label>Rigs Slot</label></div>
                        @foreach (var module in Model.ItemsFittedRigSlot.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsDroneBay.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="dronebay" src alt/><label>Drone bay</label></div>
                        @foreach (var module in Model.ItemsDroneBay.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.ItemsCargo.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="cargohold" src alt/><label>Cargo hold</label></div>
                        @foreach (var module in Model.ItemsCargo.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                @if (Model.Implants.Any())
                {
                    <div class="itemSlot"><div class="slotHeader gradientheader"><img id="implants" src alt/><label>Implants</label></div>
                        @foreach (var module in Model.Implants.OrderBy(i => i.Item.Id))
                        {
                            @Html.Partial("KillmailItemPartialView", module, new ViewDataDictionary() { new KeyValuePair<string, object>("value", string.Format(EveCustomFormatProvider.Instance, "{0:N2}", Model.ItemValues.Any(i => i.ItemId == module.ItemId) ? Model.ItemValues.First(i => i.ItemId == module.ItemId).ItemValue * module.Quantity : 0)) })
                        }
                    </div>
                }
                <div style="padding: 5px 1px; font-weight: bold; margin-top: 10px; background: #000">
                    @if (Model.GetModulesValue() > 0)
                    {
                        <div style="display: block; margin-right: 3px; vertical-align: middle; text-align: right;">@string.Format(Thread.CurrentThread.CurrentCulture, "{1} : {0:N2} isk", Model.GetModulesValue(), Labels.modules)</div>    
                    }
                    @if (Model.GetShipValue() > 0)
                    {
                        <div style="display: block; margin-right: 3px; vertical-align: middle; text-align: right;">@string.Format(Thread.CurrentThread.CurrentCulture, "{1} : {0:N2} isk", Model.GetShipValue(), Labels.ship)</div>    
                    }
                    <div style="display: block; margin-right: 3px; vertical-align: middle; text-align: right;">@string.Format(Thread.CurrentThread.CurrentCulture, "{1} : {0:N2} isk", Model.GetTotalValue(), Labels.total)</div>
                </div>
            </div>
        </div>
        <div class="killmailDetailsRightContent">
            <div style="background: rgba(0,0,0,0.3);display: block; width: 160px; margin-left: auto; margin-right: auto; padding:5px; border-radius:4px; margin-bottom:2px;">
                <img id="mail" alt src />
                <a class="evelink" onclick="@string.Format("evekillboard.showRawKillmail('{0}',{1})", Url.Action("KillmailRaw", "Killboard"), Model.Id)">Killmail</a>
            </div>
            <div style="background: rgba(0,0,0,0.3);display: block; width: 160px; margin-left: auto; margin-right: auto; padding:5px; border-radius:4px; margin-bottom:2px;">
                <img id="savefitting" alt src />
                <a class="evelink"  href="@string.Format("{0}", EveKillboard.EveFittingFormatter.Format(Model))">@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", Labels.save_fitting)</a>
            </div>
            <div id="univers" style="background: rgba(0,0,0,0.3); margin-top: 10px; margin-bottom: 0px; width: 160px; margin-left: auto; margin-right: auto; border: 1px #2a2a2a solid; padding:5px; border-radius:4px;">
                <canvas id="map"></canvas>
            </div>
        </div>
    </div>
</div>
